package com.world.rickcloudendpoint.config;

import com.world.rickcloudendpoint.demo.QueueConfig;
import com.world.rickcloudendpoint.demo.QueueConstantKey;
import com.world.rickcloudendpoint.demo.local.LocalMqConsumerContainer;
import com.world.rickcloudendpoint.demo.local.LocalQueueFactory;
import com.world.rickcloudendpoint.demo.local.consumer.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:  队列配置
 * @author: jlsong
 * @date: 2022/06/03 20:39:30
 * @version: 1.0
 */
@Configuration
public class QueuesConfig {
    @Bean
    public LocalQueueFactory localQueueFactory(){
        return LocalQueueFactory.getInstance();
    }

    @Bean(initMethod = "init", destroyMethod = "destroy")
    public LocalMqConsumerContainer localMqConsumerContainer(@Autowired LocalQueueFactory localQueueFactory,
                                                             BusinessOneConsumer businessOne,
                                                             BusinessTwoConsumer businessTwo,
                                                             BusinessThreeConsumer businessThree,
                                                             BusinessFourConsumer businessFour,
                                                             BusinessFiveConsumer businessFive,
                                                             BusinessSixConsumer businessSix,
                                                             BusinessSevenConsumer businessSeven,
                                                             BusinessEightConsumer businessEight,

                                                             PersistedOneConsumer persistedOne,
                                                             PersistedTwoConsumer persistedTwo,
                                                             PersistedThreeConsumer persistedThree,
                                                             PersistedFourConsumer persistedFour,
                                                             PersistedFiveConsumer persistedFive,
                                                             PersistedSixConsumer persistedSix,
                                                             PersistedSevenConsumer persistedSeven,
                                                             PersistedEightConsumer persistedEight
                                                             ) {
        LocalMqConsumerContainer container = new LocalMqConsumerContainer(localQueueFactory);
        String keyPrefix = QueueConstantKey.CACHE_PREFIX.concat(":");

        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_ONE).consumer(businessOne).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_TWO).consumer(businessTwo).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_THREE).consumer(businessThree).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_FOUR).consumer(businessFour).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_FIVE).consumer(businessFive).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_SIX).consumer(businessSix).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_SEVEN).consumer(businessSeven).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.BUSINESS_EIGHT).consumer(businessEight).build());

        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_ONE).consumer(persistedOne).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_TWO).consumer(persistedTwo).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_THREE).consumer(persistedThree).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_FOUR).consumer(persistedFour).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_FIVE).consumer(persistedFive).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_SIX).consumer(persistedSix).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_SEVEN).consumer(persistedSeven).build());
        container.addConsumer(QueueConfig.builder().queue(keyPrefix + QueueConstantKey.PERSISTED_EIGHT).consumer(persistedEight).build());

        return container;
    }

}
